package com.touchstone.cloudpacs.service.impl;

import com.touchstone.cloudpacs.common.constant.UserConstant;
import com.touchstone.cloudpacs.common.exception.BusinessException;
import com.touchstone.cloudpacs.common.utils.result.ResultEnum;
import com.touchstone.cloudpacs.entity.User;
import com.touchstone.cloudpacs.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * @Description :
 * @Author : hunter
 * @Date: 2019-07-14 17:33
 * @Version: 1.0
 **/
@Service
public class BaseServiceImpl implements IBaseService {

    @Autowired
    private HttpSession session;

    @Override
    public User getCurrentUser() {
        if (session == null) {
            throw new BusinessException(ResultEnum.NO_LOGIN.getDesc());
        }
        User user = (User) session.getAttribute(UserConstant.CURRENT_USER);
        if (user == null) {
            throw new BusinessException(ResultEnum.NO_LOGIN.getDesc());
        }
        return user;
    }
}
